package com.efeichong;

import com.efeichong.jpa.annotation.EnableFastJpa;
import lombok.SneakyThrows;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;

/**
 * @author
 * @date 2020/12/03
 * @description 启动类
 */
@SuppressWarnings("SpringComponentScan")
@PropertySource("classpath:componentScan.properties")
@SpringBootApplication(scanBasePackages = "${basePackage}")
@EnableFastJpa("${basePackage}.**.dao")
@EntityScan("${basePackage}.**.entity.db")
@EnableRedisRepositories(basePackages = "${basePackage}.**.redis")
@EnableScheduling
public class Application {

    @SneakyThrows
    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
        System.out.println(" |  |  __|  |     |      _ \\  \\ \\      /   _ \\   _ \\  |     _ \\  \n" +
                " __ |  _|   |     |     (   |  \\ \\ \\  /   (   |    /  |     |  | \n" +
                "_| _| ___| ____| ____| \\___/    \\_/\\_/   \\___/  _|_\\ ____| ___/  \n");
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (path == null) {
            path = "";
        }
        System.out.println("\n----------------------------------------------------------\n\t" +
                "Application is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "\n\t" +
                "swagger-ui: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");
    }


}
